package cn.itsource.org.service.impl;

import cn.itsource.basic.utils.PageList;
import cn.itsource.org.domain.depart;
import cn.itsource.org.mapper.DeparMapper;
import cn.itsource.org.query.DepartQuery;
import cn.itsource.org.service.DeparService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DeparServiceImpl implements DeparService {
    @Autowired
    private DeparMapper mapper;
    @Override
    public void add(depart depart) {
        mapper.add(depart);
    }

    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public void update(depart depart) {
        mapper.update(depart);
    }

    @Override
    public List<depart> findAll() {
        List<depart> all = mapper.findAll();
        return all ;
    }


    @Override
    public depart fingById(Long id) {
        depart depart = mapper.findById(id);
        return depart;
    }

    @Override
    public PageList<depart> queryByPage(DepartQuery query) {
        Integer count = mapper.queryByCount(query);
        if (count==0||count==null){
            return new PageList<>(0,new ArrayList<>());
        }
        List<depart> list = mapper.queryByPage(query);
        return new PageList<>(count,list);
    }
}
